#include <cstdio>
#define int ll
typedef long long ll;

const int N = 1e5 + 5, MAX = 1e9;

int n, m, tot, rt[N];

struct Node {
  int ls, rs;
  ll sum;
} tr[N << 5];

inline void insert(int x, int& y, int l, int r, int p) {
  tr[y = ++tot] = tr[x];
  tr[y].sum += p;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (p <= mid) insert(tr[x].ls, tr[y].ls, l, mid, p);
  else
    insert(tr[x].rs, tr[y].rs, mid + 1, r, p);
}

inline ll query(int x, int y, int l, int r, int L, int R) {
  if (tr[y].sum - tr[x].sum == 0) return 0;
  if (L <= l && r <= R) return tr[y].sum - tr[x].sum;
  int mid = (l + r) >> 1;
  ll res = 0;
  if (L <= mid) res += query(tr[x].ls, tr[y].ls, l, mid, L, R);
  if (mid < R) res += query(tr[x].rs, tr[y].rs, mid + 1, r, L, R);
  return res;
}

signed main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
#endif

  scanf("%lld%lld", &n, &m);
  for (int i = 1, x; i <= n; ++i) {
    scanf("%lld", &x);
    insert(rt[i - 1], rt[i], 1, MAX, x);
  }
  for (int i = 1, l, r; i <= m; ++i) {
    scanf("%lld%lld", &l, &r);
    ll las(0), cur(0), tmp;
    while (true) {
      tmp = query(rt[l - 1], rt[r], 1, MAX, las + 1, cur + 1);
      if (tmp) {
        las = cur + 1;
        cur += tmp;
      } else
        break;
    }
    printf("%lld\n", cur + 1);
  }
  return 0;
}
